package com.hbzhit.modules.cm.controller;

import com.hbzhit.common.annotation.SysLog;
import com.hbzhit.common.utils.PageUtils;
import com.hbzhit.common.utils.R;
import com.hbzhit.modules.cm.entity.ContentEntity;
import com.hbzhit.modules.cm.form.ContentListQueryForm;
import com.hbzhit.modules.cm.form.ContentPageQueryForm;
import com.hbzhit.modules.cm.service.ContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 内容发布
 *
 * @author hbzhit
 * @date 2019-07-23 15:25:46
 */
@Api(tags = {"内容发布"})
@RestController
@RequestMapping("cm/content")
public class ContentController {
    @Autowired
    private ContentService contentService;

    /**
     * 分页列表
     */
    @ApiOperation(value = "查询分页数据")
    @GetMapping("/page")
    public R<PageUtils<ContentEntity>> page(ContentPageQueryForm params) {
        PageUtils<ContentEntity> page = contentService.queryPage(params);

        return R.ok(page);
    }

    /**
     * 无分页列表
     */
    @ApiOperation(value = "查询列表数据")
    @GetMapping("/list")
    public R<List<ContentEntity>> list(ContentListQueryForm params) {
        List<ContentEntity> list = contentService.queryList(params);

        return R.ok(list);
    }

    /**
     * 信息
     */
    @ApiOperation(value = "根据ID查询详细数据")
    @GetMapping("/info/{id}")
    public R<ContentEntity> info(@PathVariable("id") Long id) {
        ContentEntity content = contentService.getById(id);

        return R.ok(content);
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增数据")
    @SysLog("新增内容发布")
    @PostMapping("/save")
    public R save(@RequestBody ContentEntity content) {
        contentService.save(content);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新数据")
    @SysLog("更新内容发布")
    @PostMapping("/update")
    public R update(@RequestBody ContentEntity content){
        contentService.updateById(content);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除数据")
    @SysLog("删除内容发布")
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        contentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
